import { useEffect, useState } from 'react';
import { fetchList, addUser, deleteUser } from '@/api/user';
import { UserProps } from '@/types/userTypes';

/**
 * key传入，如果key发生变化就会重新获取数据
 * @param key 
 * @returns 
 */
export function useUserList(key: number) {
    const [users, setUsers] = useState<UserProps[]>([]);
    useEffect(() => {
        // 获取数据
        (async () =>{
            const res = await fetchList();
            if (res.code === 0) {
                setUsers(res.data);
            }
            
        })();
    }, [key]);

    return [users, setUsers];
}